/** 创建组件对象 * */
var benchmarkTree = new Tree();
var benchmarkTab = new Tab();
var benchmarkDialog = new Dialog();
var benchmarkAjax = new Ajax();
var currentWindow = "";
var tabs = {};
var nodeObj;

/** 页面加载完执行 * */
$(function() {
	initScript();
	initBenchmarkTree();
	getNodeByNodeId("root_root");
	initTabs();
	var currentTable = [];
	benchmarkPageQuery("root_root");
});

/** 初始化script * */
function initScript() {
	loadScript(appPath + "/project-yddemo/benchmark/locale/Benchmark_" + appLocale
			+ ".js"); // 1.加载国际化js*
}

function initTabs() {
	tabs.benchmarkList = {
		id : "benchmarkList",
		text : benchmarkLocale.text.benchmarkRoot,
		src : requestPath + "/yddemo/benchmarks/page/grid",
		isClose : false,
		isActive : false
	};
}


function intiBenchmarkTab(currentTable) {
	benchmarkTab.initTab({
		divId : "benchmarkTabDiv", // 归属div*
		isEnable : true,
		tabs : currentTable,
		tabClickFun : function(data) {
			if (data == "benchmarkList") {
				$("[tabid = 'benchmarkList']")[1].contentWindow
						.resetTableHeight();
				$("[tabid = 'benchmarkList']")[1].contentWindow.benchmarkTable
						.refreshTbodyHeight();
			}
		}
	});
}

function initBenchmarkTree() {
	benchmarkTree.initTree({
		divId : "benchmarkTreeDiv", // 归属div*
		ajaxType : "ajax",
		root : {
			nodeId : "root_root",
			text : benchmarkLocale.text.benchmarkRoot,
			leaf : false,
			expanded : true
		},
		dataAjax : { // 数据源ajax*
			url : requestPath + "/yddemo/benchmarks", // 请求url*
			async : false, // 是否异步*
			type : "GET" // 请求类型*
		},
		align : { // 元素顺序
			left : "expand",
			right : "check",
			center : "text"
		},
		checkIcon : staticPath + "/skin/" + skinType
				+ "/icon/Button_tree_check.png", // 选中图标
		partcheckIcon : staticPath + "/skin/" + skinType
				+ "/icon/Button_tree_partcheck.png", // 部分选图标
		uncheckIcon : staticPath + "/skin/" + skinType
				+ "/icon/Button_tree_uncheck.png", // 未选图标
		expandIcon : staticPath + "/skin/" + skinType
				+ "/icon/Button_main_expand.png", // 展开图标
		closeIcon : staticPath + "/skin/" + skinType
				+ "/icon/Button_main_shrink.png", // 闭合图标
		textClickFun : function(nodeId) { // 文本单击事件*
			benchmarkTree.expandDefaultFun(nodeId);
			benchmarkPageQuery(nodeId);
		},
		expandFun : function(nodeId) { // 展开单击事件*
			benchmarkTree.expandDefaultFun(nodeId);
			benchmarkPageQuery(nodeId);
		},
	});
}

function benchmarkPageQuery(nodeId) {
	getNodeByNodeId(nodeId);
	nodeObj = benchmarkTree.getNode(nodeId);
	if (nodeObj.entityType == "IndicatorPackage") {
		var currentTable = [];
		currentTable[0] = tabs.benchmarkList;
		intiBenchmarkTab(currentTable,nodeId);
	}
	var activeSpan = $(".treeLi[nodeId='" + nodeId + "']").find(".textSpan")[0];
	benchmarkTree.activeNode(activeSpan);
}

function getNodeByNodeId(nodeId) {
	var nodeObj = benchmarkTree.getNode(nodeId);
	sessionStorage.parentId = nodeObj.id;
	sessionStorage.nodeId = nodeObj.nodeId;
	sessionStorage.entityType = nodeObj.entityType;
	if (nodeObj.entityType == "IndicatorPackage") {
		initTabs();
	}
}